package com.lyj.book.controller;

import com.lyj.book.common.bean.Response;
import com.lyj.book.dao.mappper.SysConfigMapper;
import com.lyj.book.dao.model.SysConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuyj
 * @create 2018-01-31 10:51
 **/
@RestController
@RequestMapping("sysconfig")
@Slf4j
@Api("配置文件")
public class SysConfigRest {

    @Autowired
    private SysConfigMapper sysConfigMapper;


    /**
     * 获取配置信息
     *
     * @param id
     * @return
     */
    @ApiOperation("获取配置信息")
    @GetMapping("config/{id}")
    public Response getSysConfig(@PathVariable String id){
        log.info("获取配置信息id[{}]",id);
        SysConfig sysConfig = sysConfigMapper.selectByPrimaryKey(id);
        return new Response().success(sysConfig);
    }


    /**
     * 添加配置信息
     *
     * @param sysConfig
     * @return
     */
    @PostMapping("config")
    @ApiOperation("添加配置信息")
    public Response postSysConfig(@ModelAttribute SysConfig sysConfig){
        log.info("添加配置信息："+sysConfig.toString());
        sysConfigMapper.insert(sysConfig);
        return new Response().success();
    }




}
